<?php

class Hocphi extends MY_Admin
{
	// Protected or private properties
	protected $_template;
	
	// Constructor
	public function __construct()
	{
		parent::__construct();

		// Check if the logged user is an administrator
		//$this->access_library->check_access();
		// Load needed models, libraries, helpers and language files
		$this->load->module_model('admin', 'hocphi_model', 'hocphi');
		$this->load->module_language('admin', 'general');
		$this->load->module_language('admin', 'hocphi');
		$this->user = $this->access->get_user();
		$this->load->helper('url'); 
		//You should autoload this one ;)
	}

	// Public methods
	public function index() 
	{
		$this->access->restrict('Admin.Hocphi.Index');
		$data['ItemID'] = 'User';
		$data['title'] = 'Bảng danh sách thu học phí';
		$data['description'] = 'Bảng danh sách thu học phí';
		$this->access->restrict();
		$this->load->library('basic_library');
		$this->load->library('pagination');
		
		$config = array();
		$config['base_url'] = base_url().'admin/hocphi/';
		$config['total_rows'] = $this->hocphi->count_all_hocphi();
		$config['per_page'] = 40;
		$config['uri_segment'] = 3;
		$config['num_links'] = 5;
		$config['first_link'] = 'First';
        $config['last_link'] = 'Last';
        $config['next_link'] = 'Next';
        $config['prev_link'] = 'Prev';
		$this->pagination->initialize($config);
		$page = ($this->uri->segment(3))? $this->uri->segment(3):0;
		
		$data['allhocphi'] = $this->hocphi->get_all_hocphi($config['per_page'], $page);
		$data['links'] = $this->pagination->create_links();		
		
		$this->_template['page']	= 'hocphi/list';
		$this->system_library->load($this->_template['page'], $data, TRUE);
	}
	
	public function search()
	{
		$data['ItemID'] = 'User';
		$data['title'] = 'Tìm kiếm thông tin';
		$data['description'] = 'Tìm kiếm thông tin';
		$data['search_keyword'] = trim($this->input->post('keyword', TRUE));
		if($data['search_keyword']!=='')
		{
			$data['result'] = $this->giaovien->search_data($data['search_keyword']);
			
				$this->_template['page']	= 'giaovien/result';
				$this->system_library->load($this->_template['page'], $data, TRUE);
			
			
		}
		else
		{
			redirect('admin/giaovien', 'refresh');
		}
	}
	
	public function check_magv()
	{
        if($this->giaovien->check_magv())
        {
            $this->form_validation->set_message('check_magv','MAGV đã tồn tại, vui lòng chọn lại');
            return false;
        }
        else
        {
            
            return true;
        }
    }
	public function check_cmnd()
	{
        if($this->giaovien->check_cmnd())
        {
            $this->form_validation->set_message('check_cmnd','CMND đã tồn tại, vui lòng chọn lại');
            return false;
        }
        else
        {
            
            return true;
        }
    }

    public function miengiam()
    {
    	///$this->access->restrict('Admin.Hocphi.Miengiam');
		$data['ItemID'] = 'User';
		$data['title'] = 'Danh sách Học viên được miễn giảm học phí';
		$data['description'] = 'Danh sách Học viên được miễn giảm học phí';
		$this->load->library('basic_library');
		$this->load->library('pagination');
		
		$config = array();
		$config['base_url'] = base_url().'admin/hocphi/';
		$config['total_rows'] = $this->hocphi->count_all_miengiam();
		$config['per_page'] = 40;
		$config['uri_segment'] = 3;
		$this->pagination->initialize($config);
		$page = ($this->uri->segment(3))? $this->uri->segment(3):0;
		
		$data['allhocphi'] = $this->hocphi->get_all_miengiam($config['per_page'], $page);
		$data['links'] = $this->pagination->create_links();		
		
		$this->_template['page']	= 'hocphi/miengiam';
		$this->system_library->load($this->_template['page'], $data, TRUE);
    }
    
    public function saveeditprice()
    {
    	$id = $this->input->post('id');
		//echo $product_id;
		//$user_id = $this->session->userdata('id');
		
		$price = $this->input->post('price');
		//log_message('DEBUG',' heariing '. $price . ' | '. $product_id);
		$json = array();
		if($this->hocphi->edit_hocphi($id, $price) > 0)
		{
			$json['result'] = 1;
		}
		else
		{
			$json['result'] = 1;
		}
		
		echo json_encode($json);
    }
	
	public function delete($id)
	{
		$this->hocphi->delete_hocphi($id);
		$this->session->set_flashdata('message', lang('successfully_deleted'));
		redirect('admin/hocphi', 'refresh');
	}

	//Edit product
	public function edit($id)
	{
		$this->access->restrict('Admin.Hocphi.Edit');
		//metadata
		$data['ItemID']		 = 'User';
		$data['title']		 = "Sửa thông tin sinh viên"; 
		$data['description'] = "Sửa thông tin sinh viên"; 
		$data['info'] 		 = $this->hocphi->get_hocphi_info($id);
		$data['thongtinkhoa']		 = $this->hocphi->get_tenkhoa();
		
		$this->form_validation->set_rules('tengv', 'lang:th_hoten', 'required');
		$this->form_validation->set_rules('email', 'lang:th_email', 'required|xss_clean|trim|valid_email');
		$this->form_validation->set_rules('diachi','lang:th_diachi','required|max_length[255]');
		$this->form_validation->set_rules('didong','lang:th_didong','required|max_length[12]');
		$this->form_validation->set_rules('gioitinh','lang:th_gioitinh','numeric');
		$this->form_validation->set_rules('makhoa','lang:th_khoa','');
					
		$this->form_validation->set_error_delimiters('', '<br />');
		
		if($this->form_validation->run() == TRUE)
		{
			$this->giaovien->edit_giaovien($id);
			$this->session->set_flashdata('message', lang('successfully_edited'));	
			redirect('admin/giaovien', 'refresh');	
		}	
		$this->_template['page']	= 'giaovien/edit';
		$this->system_library->load($this->_template['page'], $data, TRUE);
	}
	
	
	
	public function enable($id = null)
	{
		if ($id == null)
		{
			$id = $this->input->post('id');
		}
			
		$this->giaovien->change_status_giaovien($id,1);
		redirect('admin/giaovien', 'refresh');
		
	}
	public function disable($id = null)
	{
		if ($id == null)
		{
			$id = $this->input->post('id');
		}
			
		$this->giaovien->change_status_giaovien($id,0);
		redirect('admin/giaovien', 'refresh');
	}
}

/* End of file jobs.php */